package com.itheima.sc.web.sms;

import com.itheima.sc.config.ComException;
import com.itheima.sc.pojo.sms.FlashPromotion;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.sms.SmsFlashService;
import com.itheima.sc.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flash")
public class SmsFlashController {

    @Autowired
    private SmsFlashService smsFlashService;

    //根据活动名称分页查询
    @GetMapping("/list")
    public Result getAll(String keyword, @RequestParam(name = "pageNum",defaultValue = "1") String page, @RequestParam(value = "pageSize",defaultValue = "5") String pageSize){
        PageResult pageResult = smsFlashService.getAll(keyword, page, pageSize);
        return Result.success(pageResult);
    }
    //添加活动
    @PostMapping("/create")
    public Result addFlash(@RequestBody FlashPromotion flashPromotion){
        smsFlashService.addFlash(flashPromotion);
        return Result.success(null);
    }
    //删除活动
    @PostMapping("/delete/{id}")
    public Result deleteFlash(@PathVariable("id")Long id){
        smsFlashService.deleteFlash(id);
        return Result.success(null);
    }
    //修改上下线状态
    @PostMapping("/update/status/{id}")
    public Result  updateStatusFlash(@PathVariable("id")Long id,int status){
        smsFlashService.updateStatusFlash(id,status);
        return Result.success(null);
    }
    //编辑活动
    @PostMapping("/update/{id}")
    public Result  updateFlash(@RequestBody FlashPromotion flashPromotion){
        smsFlashService.updateFlash(flashPromotion);
        return Result.success(null);
    }
    //获取活动详情
    @GetMapping("/{id}")
    public Result getFlashInfo(@PathVariable("id")Long id){
        FlashPromotion flashInfo = smsFlashService.getFlashInfo(id);
        return Result.success(flashInfo);
    }



}
